How to display image in html image tag - node.js [on hold]
Posted
by
ykel
on Programmers
See other posts from Programmers
or by ykel
Published on 2013-06-28T12:44:32Z
Indexed on
2013/06/28
16:29 UTC
Read the original article
Hit count: 305
node.js
I use the following code to store image to file system and to retrieve the image, I would like to display the retrieved image on html image tag, hower the image is rendered on the response page but not on the html image tag.
here is my html image tag:
<img src="/show">
THIS CODE RETREIVES THE IMAGE:
app.get('/show', function (req, res) {
var FilePath=__dirname+"/uploads/3562_564927103528411_1723183324_n.jpg";
fs.readFile(FilePath,function(err,data){
if(err)throw err;
console.log(data);
res.writeHead(200, {'Content-Type': 'image/jpeg'});
res.end(data); // Send the file data to the browser.
})
});
© Programmers or respective owner